package com.fh.utils.swagger;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2 // 启用 Swagger
public class SwaggerConfig {
    
    @Bean
    public Docket docket(SwaggerProperties properties){
        
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo(properties))
                //分组名称
                .groupName(properties.getGroupName())
                .select()
                //这里指定Controller扫描包路径
                .apis(RequestHandlerSelectors.basePackage(properties.getBasePackage()))
                .paths(PathSelectors.any())
                .build();
    }
     
    private ApiInfo apiInfo(SwaggerProperties properties) {

        Contact contact = new Contact(properties.getName(), properties.getUrl(), properties.getEmail());
        return new ApiInfoBuilder()
                .title(properties.getTitle())
                .description(properties.getDescription())
                .contact(contact)
                .version(properties.getVersion())
                .build();
    }
}
